/**
 * 包含N个数据库集合数据的模块
 */
const mongoose = require('mongoose')

mongoose.connect('mongodb://127.0.0.1:27017/gzhipin', { useNewUrlParser: true, useUnifiedTopology: true })

const conn = mongoose.connection

conn.on('connected', () => {
  console.log('db is conented success');
})

const userSchema = mongoose.Schema({
  username: { type: String, required: true }, // 用户名
  password: { type: String, required: true }, // 密码
  type: { type: String, required: true }, // 用户类型
  header: { type: String },     // 头像名称 
  post: { type: String },      // 职位
  info: { type: String },     // 个人或职位简介
  company: { type: String },  // 公司名称
  salary: { type: String }, //月薪
})
const UserModel = mongoose.model('user', userSchema)
// 向外暴露Model
exports.UserModel = UserModel

// 创建一个chatmodel
const chatSchema = mongoose.Schema({
  from: { type: String, required: true },
  to: { type: String, required: true },
  chat_id: { type: String, required: true },
  content: { type: String, required: true },
  read: { type: Boolean, default: false },
  create_time: { type: Number }
})
const chatModel = mongoose.model('chatlists', chatSchema)
exports.chatModel = chatModel



// module.exports = xxx 暴露一个
// exports.xxx 暴露多个
// exports.yyy 暴露多个